package com.king.cms.common;

import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class HttpSessionManager {
   HttpSession session = null;
   UserObj user = null;
   ServletContext application=null;
   public HttpSessionManager(ServletContext context,HttpServletRequest request, HttpServletResponse response){
	   session = request.getSession();
	   application = context;
   }
   public void logout(){
	   {
		   if (this.user == null 
		     && this.session.getAttribute("user")==null)
		   {
		     return;
		   }

		   Vector activeSessions = (Vector) this.application.getAttribute("activeSessions");
		   if (activeSessions != null)
		   {
		     activeSessions.remove(this.session);
		     application.setAttribute("activeSessions",activeSessions);
		   }

		   java.util.Enumeration e = this.session.getAttributeNames();

		   while (e.hasMoreElements())
		   {
		     String s = (String)e.nextElement();
		     this.session.removeAttribute(s);
		   } 
		   this.user = null;
		  }

   }
}
